package com.leaf.spring.y201907.day22.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Producer {

	public static void sendByExchange(String message) throws Exception {
		Connection connection = ConnectionUtil.getConnection();
		Channel channel = connection.createChannel();
		channel.queueDeclare(ConnectionUtil.QUEUE_NAME, false, false, false, null);
		channel.queueBind(ConnectionUtil.QUEUE_NAME, ConnectionUtil.EXCHANGE_NAME, "fanout");
		channel.basicPublish(ConnectionUtil.EXCHANGE_NAME, "", null, message.getBytes());
//		channel.basicPublish("", ConnectionUtil.QUEUE_NAME, null, message.getBytes());
		System.out.println("发送的消息为：" + message);
		channel.close();
		connection.close();
	}

	public static void main(String[] args) throws Exception {
		Producer producer = new Producer();
		producer.sendByExchange("hello1");
	}

}
